#coding: utf-8

# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


class Solution:
    cur = 0

    # 一个链表，移除倒数第n个元素，返回头结点
    def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
        if head == None:
            return None
        head.next = self.removeNthFromEnd(head.next,n)
        self.cur = self.cur + 1
        if n == self.cur:
            return head.next
        return head


if __name__ == '__main__':
    solu = Solution()
